package com.doit.day01;

import org.apache.zookeeper.KeeperException;
import org.apache.zookeeper.WatchedEvent;
import org.apache.zookeeper.Watcher;
import org.apache.zookeeper.ZooKeeper;

import java.io.IOException;
import java.util.List;

public class _01_zk的监听机制 {
    public static void main(String[] args) throws Exception {
        String zkConnect = "linux01:2181,linux02:2181,linux03:2181";
        int timeOut = 1000;
        ZooKeeper zk = new ZooKeeper(zkConnect, timeOut, new Watcher() {
            @Override
            public void process(WatchedEvent event) {
                System.out.println("hello");
            }
        });
        /*List<String> children = zk.getChildren("/", new Watcher() {
            @Override
            public void process(WatchedEvent event) {
                System.out.println("hhh");
               *//* try {
                    zk.getChildren("/",this);
                } catch (Exception e) {
                    e.printStackTrace();
                }*//*
            }
        });*/

        //getData
        byte[] data = zk.getData("/aaa", new Watcher() {
            @Override
            public void process(WatchedEvent event) {
                System.out.println("hehehe");
            }
        }, null);




        /*for (String child : children) {
            System.out.println(child);
        }*/

        Thread.sleep(Long.MAX_VALUE);

    }
}
